package com.yuantu.judiciary.common;

import com.yuantu.judiciary.exception.ServiceException;

/**
 * 返回工具类
 *
 * @author syw
 * @since 2023-06-07
 **/
public class ResponseFactory {

    /**
     * 成功
     */
    public static <T> Response<T> okResponse(T data) {
        return new Response<>(SysCode.SUCCESS.getCode(), data, SysCode.SUCCESS.getMessage());
    }

    /**
     * 失败
     */
    public static <T> Response<T> errResponse(int errCode, String errMessage) {
        return new Response<T>(errCode, null, errMessage);
    }

    public static <T> Response<T> errResponse(String errMessage) {
        return new Response<T>(500, null, errMessage);
    }

    /**
     * 失败
     */
    public static Response<?> errResponse(ServiceException err) {
        return new Response<>(err.getCode(), null, err.getMessage());
    }

}
